package com.sealer.pattern.behavioral.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by sealer on 17/04/06.
 */
public class Subject {
    private List<Observer> observers = new ArrayList<>();
    private int state;

    public void attach(Observer observer) {
        observers.add(observer);
    }

    public int getState() {
        return state;
    }

    public void setState(int in) {
        state = in;
        notifyA();
    }

    private void notifyA() {
        for (Observer observer : observers) {
            observer.update();
        }
    }

}
